home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / dev / gui / DesignerV1_53.lha / Designer / Developer / Developer.lha / C / example / example.c
C/C++ Source or Header  |  1995-04-26  |  23KB  |  775 lines

  1. #define abs
  2.  
  3. #include <stdio.h>
  4. #include <stdarg.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <ctype.h>
  8. #include <dos/dos.h>
  9. #include <exec/exec.h>
  10. #include <exec/types.h>
  11. #include <clib/exec_protos.h>
  12. #include <clib/utility_protos.h>
  13. #include <clib/alib_protos.h>
  14. #include <utility/tagitem.h>
  15. #include <dos/dosasl.h>
  16. #include <dos/rdargs.h>
  17. #include <dos/dostags.h>
  18. #include <clib/dos_protos.h>
  19. #include <intuition/intuition.h>
  20. #include <intuition/screens.h>
  21. #include <intuition/intuition.h>
  22. #include <intuition/gadgetclass.h>
  23. #include <libraries/gadtools.h>
  24. #include <graphics/gfxbase.h>
  25. #include <workbench/workbench.h>
  26. #include <graphics/scale.h>
  27. #include <clib/wb_protos.h>
  28. #include <clib/intuition_protos.h>
  29. #include <clib/gadtools_protos.h>
  30. #include <clib/graphics_protos.h>
  31. #include <clib/utility_protos.h>
  32. #include <clib/diskfont_protos.h>
  33.  
  34. #include "producer_protos.h"
  35. #include "producer.h"
  36.  
  37. struct    ProducerNode *pn = NULL;
  38. UBYTE  *ProjectName;
  39. long    LineCount;  
  40. BPTR    OutputFile = 0;
  41.  
  42. char * LoadErrors[] =
  43. {
  44.     "No Error",
  45.     "No filename",
  46.     "No file",
  47.     "No IFF Handle",
  48.     "No memory",
  49.     "Read error",
  50.     "File structure error",
  51.     "Not Designer file",
  52.     "File Version Too Small",
  53.     "File Version Too Large"
  54. };
  55.  
  56. VOID AddEnding( UBYTE *buff, UBYTE *end )
  57. {
  58.     UBYTE       *pos;
  59.  
  60.     if ( pos = strrchr( buff, '.' ))
  61.         *pos = 0;
  62.     strcat( buff, end );
  63. }
  64.  
  65. BPTR OpenOutputFile( UBYTE *ending )
  66. {
  67.     UBYTE       Name[512];
  68.  
  69.     strcpy( &Name[ 0 ], ProjectName );
  70.     AddEnding( &Name[ 0 ], ending );
  71.     return( Open( &Name[ 0 ], MODE_NEWFILE ));
  72. }
  73.  
  74. ULONG MyFPrintf( BPTR stream, UBYTE *format, ... )
  75. {
  76.     va_list         arguments;
  77.     ULONG           rc;
  78.  
  79.     va_start( arguments, format );
  80.  
  81.     rc = VFPrintf( stream, format, arguments );
  82.  
  83.     va_end( arguments );
  84.  
  85.     return( rc );
  86. }
  87.  
  88. /**********************************************************/
  89. /*                                                        */
  90. /*  Print out information about window passed to function */
  91. /*                                                        */
  92. /**********************************************************/
  93.  
  94. void ProcessWindow(struct WindowNode *wn)
  95. {
  96.     struct SmallImageNode *sin;
  97.     struct BevelBoxNode *bb;
  98.     struct TextNode *tn;
  99.     struct GadgetNode *gn;
  100.     
  101.     MyFPrintf( OutputFile, "\nWindow              :  %s\n",  GetTagData( WA_Title, 0, wn->wn_TagList));
  102.     MyFPrintf( OutputFile, "  WA_Left           :  %ld\n",  GetTagData( WA_Left , 0, wn->wn_TagList));
  103.     MyFPrintf( OutputFile, "  WA_Top            :  %ld\n",  GetTagData( WA_Top  , 0, wn->wn_TagList));
  104.     
  105.     LineCount+=4;
  106.     
  107.     if (TagInArray(WA_Width, (Tag *)wn->wn_TagList))
  108.         {
  109.         MyFPrintf( OutputFile, "  WA_Width          :  %ld\n",  GetTagData( WA_Width, 0, wn->wn_TagList));
  110.         LineCount+=1;
  111.         }
  112.     if (TagInArray(WA_Height, (Tag *)wn->wn_TagList))
  113.         {
  114.         MyFPrintf( OutputFile, "  WA_Height         :  %ld\n",  GetTagData( WA_Height, 0, wn->wn_TagList));
  115.         LineCount+=1;
  116.         }
  117.     if (TagInArray(WA_InnerWidth, (Tag *)wn->wn_TagList))
  118.         {
  119.         MyFPrintf( OutputFile, "  WA_InnerWidth     :  %ld\n",  GetTagData( WA_InnerWidth, 0, wn->wn_TagList));
  120.         LineCount+=1;
  121.         }
  122.     if (TagInArray(WA_InnerHeight, (Tag *)wn->wn_TagList))
  123.         {
  124.         MyFPrintf( OutputFile, "  WA_InnerHeight    :  %ld\n",  GetTagData( WA_InnerHeight, 0, wn->wn_TagList));
  125.         LineCount+=1;
  126.         }
  127.     
  128.     MyFPrintf( OutputFile, "  WA_MinWidth       :  %ld\n",  GetTagData( WA_MinWidth  , 0, wn->wn_TagList));
  129.     MyFPrintf( OutputFile, "  WA_MaxWidth       :  %ld\n",  GetTagData( WA_MaxWidth  , 0, wn->wn_TagList));
  130.     MyFPrintf( OutputFile, "  WA_MinHeight      :  %ld\n",  GetTagData( WA_MinHeight , 0, wn->wn_TagList));
  131.     MyFPrintf( OutputFile, "  WA_MaxHeight      :  %ld\n",  GetTagData( WA_MaxHeight , 0, wn->wn_TagList));
  132.     
  133.     
  134.     if (TagInArray(WA_ScreenTitle, (Tag *)wn->wn_TagList))
  135.         {
  136.         MyFPrintf( OutputFile, "  WA_ScreenTitle    :  %s\n",  GetTagData( WA_ScreenTitle, 0, wn->wn_TagList));
  137.         LineCount+=1;
  138.         }
  139.  
  140.     if (TagInArray(WA_SizeGadget, (Tag *)wn->wn_TagList))
  141.         {
  142.         MyFPrintf( OutputFile, "  WA_SizeGadget     :  TRUE\n");
  143.         LineCount+=1;
  144.         if (TagInArray(WA_SizeBRight, (Tag *)wn->wn_TagList))
  145.             {
  146.             MyFPrintf( OutputFile, "  WA_SizeBRight     :  TRUE\n");
  147.             LineCount+=1;
  148.             }
  149.         if (TagInArray(WA_SizeBBottom, (Tag *)wn->wn_TagList))
  150.             {
  151.             MyFPrintf( OutputFile, "  WA_SizeBBottom    :  TRUE\n");
  152.             LineCount+=1;
  153.             }
  154.         }
  155.     if (TagInArray(WA_DragBar, (Tag *)wn->wn_TagList))
  156.         {
  157.         MyFPrintf( OutputFile, "  WA_DragBar        :  TRUE\n");
  158.         LineCount+=1;
  159.         }
  160.     if (TagInArray(WA_DepthGadget, (Tag *)wn->wn_TagList))
  161.         {
  162.         MyFPrintf( OutputFile, "  WA_DepthGadget    :  TRUE\n");
  163.         LineCount+=1;
  164.         }
  165.     if (TagInArray(WA_CloseGadget, (Tag *)wn->wn_TagList))
  166.         {
  167.         MyFPrintf( OutputFile, "  WA_CloseGadget    :  TRUE\n");
  168.         LineCount+=1;
  169.         }
  170.     if (TagInArray(WA_ReportMouse, (Tag *)wn->wn_TagList))
  171.         {
  172.         MyFPrintf( OutputFile, "  WA_ReportMouse    :  TRUE\n");
  173.         LineCount+=1;
  174.         }
  175.     if (TagInArray(WA_NoCareRefresh, (Tag *)wn->wn_TagList))
  176.         {
  177.         MyFPrintf( OutputFile, "  WA_NoCareRefresh  :  TRUE\n");
  178.         LineCount+=1;
  179.         }
  180.     if (TagInArray(WA_Borderless, (Tag *)wn->wn_TagList))
  181.         {
  182.         MyFPrintf( OutputFile, "  WA_Borderless     :  TRUE\n");
  183.         LineCount+=1;
  184.         }
  185.     if (TagInArray(WA_Backdrop, (Tag *)wn->wn_TagList))
  186.         {
  187.         MyFPrintf( OutputFile, "  WA_Backdrop       :  TRUE\n");
  188.         LineCount+=1;
  189.         }
  190.     if (TagInArray(WA_GimmeZeroZero, (Tag *)wn->wn_TagList))
  191.         {
  192.         MyFPrintf( OutputFile, "  WA_GimmeZeroZero  :  TRUE\n");
  193.         LineCount+=1;
  194.         }
  195.     if (TagInArray(WA_Activate, (Tag *)wn->wn_TagList))
  196.         {
  197.         MyFPrintf( OutputFile, "  WA_Activate       :  TRUE\n");
  198.         LineCount+=1;
  199.         }
  200.     if (TagInArray(WA_RMBTrap, (Tag *)wn->wn_TagList))
  201.         {
  202.         MyFPrintf( OutputFile, "  WA_RMBTrap        :  TRUE\n");
  203.         LineCount+=1;
  204.         }
  205.     if (TagInArray(WA_Dummy+0x030, (Tag *)wn->wn_TagList))
  206.         {
  207.         MyFPrintf( OutputFile, "  WA_Dummy+0x030    :  TRUE\n");
  208.         LineCount+=1;
  209.         }
  210.     if (TagInArray(WA_Dummy+0x032, (Tag *)wn->wn_TagList))
  211.         {
  212.         MyFPrintf( OutputFile, "  WA_Dummy+0x032    :  TRUE\n");
  213.         LineCount+=1;
  214.         }
  215.     if (TagInArray(WA_Dummy+0x037, (Tag *)wn->wn_TagList))
  216.         {
  217.         MyFPrintf( OutputFile, "  WA_Dummy+0x037    :  TRUE\n");
  218.         LineCount+=1;
  219.         }
  220.     if (TagInArray(WA_SimpleRefresh, (Tag *)wn->wn_TagList))
  221.         {
  222.         MyFPrintf( OutputFile, "  WA_SimpleRefresh  :  TRUE\n");
  223.         LineCount+=1;
  224.         }
  225.     if (TagInArray(WA_SmartRefresh, (Tag *)wn->wn_TagList))
  226.         {
  227.         MyFPrintf( OutputFile, "  WA_SmartRefresh   :  TRUE\n");
  228.         LineCount+=1;
  229.         }
  230.     if (TagInArray(WA_AutoAdjust, (Tag *)wn->wn_TagList))
  231.         {
  232.         MyFPrintf( OutputFile, "  WA_AutoAdjust     :  TRUE\n");
  233.         LineCount+=1;
  234.         }
  235.     if (TagInArray(WA_MenuHelp, (Tag *)wn->wn_TagList))
  236.         {
  237.         MyFPrintf( OutputFile, "  WA_MenuHelp       :  TRUE\n");
  238.         LineCount+=1;
  239.         }
  240.     if (TagInArray(WA_Zoom, (Tag *)wn->wn_TagList))
  241.         {
  242.         MyFPrintf( OutputFile, "  WA_Zoom           :  yep, its here all right.\n");
  243.         LineCount+=1;
  244.         }
  245.     if (TagInArray(WA_MouseQueue, (Tag *)wn->wn_TagList))
  246.         {
  247.         MyFPrintf( OutputFile, "  WA_MouseQueue     :  %ld\n",GetTagData( WA_MouseQueue  , 0, wn->wn_TagList));
  248.         LineCount+=1;
  249.         }
  250.     if (TagInArray(WA_RptQueue, (Tag *)wn->wn_TagList))
  251.         {
  252.         MyFPrintf( OutputFile, "  RptQueue          :  %ld\n",GetTagData( WA_RptQueue  , 0, wn->wn_TagList));
  253.         LineCount+=1;
  254.         }
  255.     if (TagInArray(WA_PubScreenFallBack, (Tag *)wn->wn_TagList))
  256.         {
  257.         MyFPrintf( OutputFile, "  WA_PubScreenFallBack  :  TRUE\n");
  258.         LineCount+=1;
  259.         }
  260.     if (TagInArray(WA_PubScreen, (Tag *)wn->wn_TagList))
  261.         {
  262.         MyFPrintf( OutputFile, "  WA_PubScreen      :  Have to deal with this one.\n");
  263.         LineCount+=1;
  264.         }
  265.     if (TagInArray(WA_CustomScreen, (Tag *)wn->wn_TagList))
  266.         {
  267.         MyFPrintf( OutputFile, "  WA_CustomScreen   :  Better expect a parameter.\n");
  268.         LineCount+=1;
  269.         }
  270.     MyFPrintf( OutputFile, "  WA_IDCMP          :  %ld\n", GetTagData( WA_IDCMP  , 0, wn->wn_TagList));
  271.     LineCount+=1;
  272.     
  273.     gn = (struct GadgetNode *)wn->wn_GadgetList.mlh_Head;
  274.     while (gn->gn_Succ)
  275.         {
  276.         MyFPrintf( OutputFile, "  Gadget\n");
  277.         MyFPrintf( OutputFile, "    Label           :  %s\n",gn->gn_Label);
  278.         MyFPrintf( OutputFile, "    Title           :  %s\n",gn->gn_Title);
  279.         MyFPrintf( OutputFile, "    Flags           :  %ld\n",gn->gn_Flags);
  280.         MyFPrintf( OutputFile, "    LeftEdge        :  %ld\n",gn->gn_LeftEdge);
  281.         MyFPrintf( OutputFile, "    TopEdge         :  %ld\n",gn->gn_TopEdge);
  282.         MyFPrintf( OutputFile, "    Width           :  %ld\n",gn->gn_Width);
  283.         MyFPrintf( OutputFile, "    Height          :  %ld\n",gn->gn_Height);
  284.         MyFPrintf( OutputFile, "    GadgetID        :  %ld\n",gn->gn_GadgetID);
  285.         MyFPrintf( OutputFile, "    Kind            :  %ld\n",gn->gn_Kind);
  286.         gn = gn->gn_Succ;
  287.         LineCount+=10;
  288.         }
  289.     
  290.     sin = (struct SmallImageNode *)wn->wn_ImageList.mlh_Head;
  291.     while(sin->sin_Succ)
  292.         {
  293.         MyFPrintf( OutputFile, "  Small Image       :  %ld, %ld, %s\n", sin->sin_LeftEdge, sin->sin_TopEdge, sin->sin_Image->in_Label );
  294.         sin = sin->sin_Succ;
  295.         LineCount+=1;
  296.         }
  297.     
  298.     bb = (struct BevelBoxNode *)wn->wn_BevelBoxList.mlh_Head;
  299.     while(bb->bb_Succ)
  300.         {
  301.         MyFPrintf( OutputFile, "  Bevel Box Node    :  %ld, %ld, %ld, %ld, %ld\n", bb->bb_LeftEdge, bb->bb_TopEdge, bb->bb_Width, bb->bb_Height, bb->bb_BevelType );
  302.         bb = bb->bb_Succ;
  303.         LineCount+=1;
  304.         }
  305.     
  306.     tn = (struct TextNode *)wn->wn_TextList.mlh_Head;
  307.     while(tn->tn_Succ)
  308.         {
  309.         MyFPrintf( OutputFile, "  Text Node         :  %ld, %ld, %s\n", tn->tn_LeftEdge, tn->tn_TopEdge, tn->tn_Title);
  310.         MyFPrintf( OutputFile, "                       %ld, %ld, %ld, %ld\n", tn->tn_FrontPen, tn->tn_BackPen, tn->tn_DrawMode, tn->tn_ScreenFont);
  311.         MyFPrintf( OutputFile, "                       %s, %ld, %ld, %ld\n", tn->tn_Font.ta_Name, tn->tn_Font.ta_YSize, tn->tn_Font.ta_Style, tn->tn_Font.ta_Flags);
  312.         LineCount+=3;
  313.         tn = tn->tn_Succ;
  314.         }
  315. }
  316.  
  317. /**********************************************************/
  318. /*                                                        */
  319. /*  Print out information about screen passed to function */
  320. /*                                                        */
  321. /**********************************************************/
  322.  
  323. void ProcessScreen(struct ScreenNode *sn)
  324. {
  325.     
  326.     UWORD * pos;
  327.     
  328.     MyFPrintf( OutputFile, "\nScreen         :  %s\n", GetTagData( SA_Title  , 0, sn->sn_TagList));
  329.     
  330.     MyFPrintf( OutputFile, "  Left Edge    :  %ld\n", GetTagData( SA_Left  , 0, sn->sn_TagList));
  331.     MyFPrintf( OutputFile, "  Top Edge     :  %ld\n", GetTagData( SA_Top   , 0, sn->sn_TagList));
  332.     MyFPrintf( OutputFile, "  Width        :  %ld\n", GetTagData( SA_Width , 0, sn->sn_TagList));
  333.     MyFPrintf( OutputFile, "  Height       :  %ld\n", GetTagData( SA_Height, 0, sn->sn_TagList));
  334.     MyFPrintf( OutputFile, "  Depth        :  %ld\n",  GetTagData( SA_Depth , 0, sn->sn_TagList));
  335.     MyFPrintf( OutputFile, "  OverScan     :  %ld\n",  GetTagData( SA_Overscan   , 0, sn->sn_TagList));
  336.  
  337.     MyFPrintf( OutputFile, "  Behind       :  %ld\n",  GetTagData( SA_Behind, 0, sn->sn_TagList));
  338.     MyFPrintf( OutputFile, "  Quiet        :  %ld\n",  GetTagData( SA_Quiet , 0, sn->sn_TagList));
  339.     MyFPrintf( OutputFile, "  ShowTitle    :  %ld\n",  GetTagData( SA_Depth , 1, sn->sn_TagList));
  340.     MyFPrintf( OutputFile, "  AutoScroll   :  %ld\n",  GetTagData( SA_AutoScroll , 0, sn->sn_TagList));
  341.     MyFPrintf( OutputFile, "  DisplayID    :  %lx\n", GetTagData( SA_DisplayID  , 0, sn->sn_TagList));
  342.     MyFPrintf( OutputFile, "  FullPalette  :  %ld\n",  GetTagData( SA_FullPalette, 0, sn->sn_TagList));
  343.     LineCount+=14;
  344.  
  345.     
  346.     if (TagInArray(SA_PubName, (Tag *)sn->sn_TagList))
  347.         {
  348.         MyFPrintf( OutputFile, "  PubName      :  %s\n",  GetTagData( SA_PubName, 0, sn->sn_TagList));
  349.         LineCount+=1;
  350.         }
  351.     if (TagInArray(SA_Type, (Tag *)sn->sn_TagList))
  352.         {
  353.         MyFPrintf( OutputFile, "  Type         :  %ld\n",  GetTagData( SA_Type, CUSTOMSCREEN, sn->sn_TagList));
  354.         LineCount+=1;
  355.         }
  356.     if (TagInArray(SA_ErrorCode, (Tag *)sn->sn_TagList))
  357.         {
  358.         MyFPrintf( OutputFile, "  ErrorCode    :  Required\n");
  359.         LineCount+=1;
  360.         }
  361.     
  362.     MyFPrintf( OutputFile, "  Draggable    :  %ld\n",  GetTagData( SA_Draggable     , 1, sn->sn_TagList));
  363.     MyFPrintf( OutputFile, "  Exclusive    :  %ld\n",  GetTagData( SA_Exclusive     , 0, sn->sn_TagList));
  364.     MyFPrintf( OutputFile, "  SharePens    :  %ld\n",  GetTagData( SA_SharePens     , 0, sn->sn_TagList));
  365.     MyFPrintf( OutputFile, "  Interleaved  :  %ld\n",  GetTagData( SA_Interleaved   , 0, sn->sn_TagList));
  366.     MyFPrintf( OutputFile, "  LikeWorkbench:  %lx\n", GetTagData( SA_LikeWorkbench , 0, sn->sn_TagList));
  367.     LineCount+=5;
  368.  
  369.     if (TagInArray(SA_BitMap, (Tag *)sn->sn_TagList))
  370.         {
  371.         MyFPrintf( OutputFile, "  BitMap       :  %ld\n",  GetTagData( SA_BitMap    , 0, sn->sn_TagList));
  372.         LineCount+=1;
  373.         }
  374.     if (TagInArray(SA_PubSig, (Tag *)sn->sn_TagList))
  375.         {
  376.         MyFPrintf( OutputFile, "  PubSig       :  %ld\n",  GetTagData( SA_PubSig    , 0, sn->sn_TagList));
  377.         LineCount+=1;
  378.         }
  379.     
  380. /* Handle DriPens */
  381.     
  382.     pos = (UWORD *)GetTagData(SA_Pens, 0, sn->sn_TagList);
  383.     MyFPrintf( OutputFile, "  Pens         :  ");
  384.     while (*pos != -1)
  385.         {
  386.         MyFPrintf( OutputFile, "%ld, ", *pos );
  387.         pos += 1;
  388.         };
  389.     MyFPrintf( OutputFile, "-1\n");
  390.     LineCount+=1;
  391.     
  392. /* Custom Palette Stuff */
  393.     
  394.     pos = (UWORD *)GetTagData( SA_Colors, 0, sn->sn_TagList);
  395.     if (pos)
  396.         {
  397.         MyFPrintf( OutputFile, "  Colors       :  ");
  398.         while( *pos !=65535 )
  399.             {
  400.             MyFPrintf( OutputFile, "%ld, ",*pos);
  401.             pos +=1;
  402.             MyFPrintf( OutputFile, "%ld, ",*pos);
  403.             pos +=1;
  404.             MyFPrintf( OutputFile, "%ld, ",*pos);
  405.             pos +=1;
  406.             MyFPrintf( OutputFile, "%ld,\n                  ",*pos);
  407.             pos +=1;
  408.             LineCount+=1;
  409.             }
  410.         MyFPrintf( OutputFile, "65535, 0, 0, 0,\n");
  411.         LineCount+=1;
  412.         }
  413. }
  414.  
  415. /*********************************************************/
  416. /*                                                       */
  417. /*  Print out information about image passed to function */
  418. /*                                                       */
  419. /*********************************************************/
  420.  
  421. void ProcessImage(struct ImageNode *in)
  422. {
  423.     UWORD *pos;
  424.     long count;
  425.     
  426.     MyFPrintf( OutputFile, "\nImage Node       :  %s\n", in->in_Label );
  427.     MyFPrintf( OutputFile, "  Width          :  %ld\n", in->in_Width);
  428.     MyFPrintf( OutputFile, "  Height         :  %ld\n", in->in_Height);
  429.     MyFPrintf( OutputFile, "  Depth          :  %ld\n", in->in_Depth);
  430.     MyFPrintf( OutputFile, "  PlanePick      :  %ld\n", in->in_PlanePick);
  431.     MyFPrintf( OutputFile, "  PlaneOnOff     :  %ld\n", in->in_PlaneOnOff);
  432.     MyFPrintf( OutputFile, "  DataSize       :  %ld\n", in->in_SizeAllocated);
  433.     MyFPrintf( OutputFile, "  MapSize        :  %ld\n", in->in_MapSize);
  434.     MyFPrintf( OutputFile, "  Colour Map     :  ");
  435.     LineCount+=10;
  436.     if (in->in_ColourMap)
  437.         {
  438.         pos = in->in_ColourMap;
  439.         count = in->in_MapSize;
  440.         while(count>0)
  441.             {
  442.             MyFPrintf( OutputFile, "%ld, ",*pos);
  443.             pos += 1;
  444.             count -= 2;
  445.             }
  446.         MyFPrintf( OutputFile, "\n");
  447.         LineCount+=1;
  448.         }
  449.     else
  450.         MyFPrintf( OutputFile, "None \n");
  451.     if (in->in_ImageData)
  452.         {
  453.         pos = in->in_ImageData;
  454.         count = 0;
  455.         LineCount+=1;
  456.         MyFPrintf( OutputFile, "  Image Data     :\n    ");
  457.         while( count < (in->in_SizeAllocated / 2) )
  458.             {
  459.             count += 1;
  460.             MyFPrintf( OutputFile, "%ld, ",*pos);
  461.             if ((count/10)*10 == count)
  462.                 {
  463.                 MyFPrintf( OutputFile, "\n    ");
  464.                 LineCount+=1;
  465.                 }
  466.             pos   += 1;
  467.             }
  468.         MyFPrintf( OutputFile, "\n");
  469.         }
  470. }
  471.  
  472. /********************************************************/
  473. /*                                                      */
  474. /*  Print out information about menu passed to function */
  475. /*                                                      */
  476. /********************************************************/
  477.  
  478. void ProcessMenu( struct MenuNode * mn)
  479. {
  480.     
  481.     struct MenuTitleNode *mt;
  482.     struct MenuItemNode *mi;
  483.     struct MenuSubItemNode *si;
  484.     
  485.     char state[7] = "      ";
  486.     long loop;
  487.     
  488.     MyFPrintf( OutputFile, "\nMenu Node    :  %s\n", mn->mn_Label );
  489.     
  490.     MyFPrintf( OutputFile, "  Front Pen  :  %ld\n", GetTagData(GTMN_FrontPen,0, mn->mn_TagList) );
  491.     
  492.     MyFPrintf( OutputFile, "  Locale     :  ");
  493.     if (mn->mn_LocaleMenu) MyFPrintf( OutputFile, "Yes\n"); else MyFPrintf( OutputFile, "No\n");
  494.     
  495.     if ( 0 == TagInArray( GTMN_TextAttr, (Tag *)mn->mn_TagList) )
  496.         MyFPrintf( OutputFile, "  Font       :  default\n" );
  497.     else
  498.         MyFPrintf( OutputFile, "  Font       :  %s\n", ((struct TextAttr *)(GetTagData(GTMN_TextAttr,0, mn->mn_TagList)))->ta_Name );
  499.     LineCount+=5;
  500.     
  501.     mt = (struct MenuTitleNode *)mn->mn_MenuList.mlh_Head;
  502.     while(mt->mt_Succ)
  503.         {
  504.         state[0]='-';
  505.         for (loop=1;loop<6;loop++)
  506.             state[loop] = '-';
  507.         if (mt->mt_Disabled)
  508.             state[0] = 'D';
  509.         MyFPrintf( OutputFile, "  Title  :  %s  %s\n", state, mt->mt_Text );
  510.         LineCount+=1;
  511.         mi = (struct MenuItemNode *)mt->mt_ItemList.mlh_Head;
  512.         while(mi->mi_Succ)
  513.             {
  514.             for (loop=0;loop<6;loop++)
  515.                 state[loop] = '-';
  516.             if (mi->mi_Disabled)        state[0]='D';
  517.             if (mi->mi_Barlabel)        state[1]='B';
  518.             if (mi->mi_MenuToggle)        state[2]='M';
  519.             if (mi->mi_Checkit)            state[3]='C';
  520.             if (mi->mi_Checked)            state[4]='C';
  521.             if (mi->mi_Graphic)            state[5]='I';
  522.             if (mi->mi_Graphic == NULL)
  523.                 MyFPrintf( OutputFile, "   Item  :  %s    %s\n", state, mi->mi_Text );
  524.             else
  525.                 MyFPrintf( OutputFile, "   Item  :  %s    %s\n", state, mi->mi_Graphic->in_Label );
  526.             LineCount+=1;
  527.             si = (struct MenuSubItemNode *)mi->mi_SubItemList.mlh_Head;
  528.             while(si->ms_Succ)
  529.                 {
  530.                 for (loop=0;loop<6;loop++)
  531.                     state[loop] = '-';
  532.                 if (si->ms_Disabled)        state[0]='D';
  533.                 if (si->ms_Barlabel)        state[1]='B';
  534.                 if (si->ms_MenuToggle)        state[2]='M';
  535.                 if (si->ms_Checkit)            state[3]='C';
  536.                 if (si->ms_Checked)            state[4]='C';
  537.                 if (si->ms_Graphic)            state[5]='I';
  538.                 if (si->ms_Graphic == NULL)
  539.                     MyFPrintf( OutputFile, "    Sub  :  %s      %s\n", state, si->ms_Text );
  540.                 else
  541.                     MyFPrintf( OutputFile, "    Sub  :  %s      %s\n", state, si->ms_Graphic->in_Label );
  542.                 LineCount+=1;
  543.                 si = si->ms_Succ;
  544.                 }
  545.             mi = mi->mi_Succ;
  546.             }
  547.         mt = mt->mt_Succ;
  548.         }
  549. }
  550.  
  551. /***********************************************************/
  552. /*                                                         */
  553. /*  Print out information about locale and current strings */
  554. /*                                                         */
  555. /***********************************************************/
  556.  
  557. void PrintLocale(struct ProducerNode *pn)
  558. {
  559.     struct LocaleNode *ln;
  560.     
  561.     /* Print Locale information and current strings */
  562.     
  563.     MyFPrintf( OutputFile, "\nLocale Info:\n");
  564.     MyFPrintf( OutputFile, "  BaseName         :  %s\n",pn->pn_BaseName);
  565.     MyFPrintf( OutputFile, "  GetString        :  %s\n",pn->pn_GetString);
  566.     MyFPrintf( OutputFile, "  BuiltInLanguage  :  %s\n",pn->pn_BuiltInLanguage);
  567.     LineCount += 5;
  568.     
  569.     ln = (struct LocaleNode *)pn->pn_LocaleList.mlh_Head;
  570.     while (ln->ln_Succ)
  571.         {
  572.         MyFPrintf( OutputFile, "    String         :  %s\n",ln->ln_String);
  573.         MyFPrintf( OutputFile, "    Label          :  %s\n",ln->ln_Label);
  574.         MyFPrintf( OutputFile, "    Comment        :  %s\n",ln->ln_Comment);
  575.         LineCount += 3;
  576.         ln = ln->ln_Succ;
  577.         }
  578. }
  579.  
  580. /********************************************************/
  581. /*                                                      */
  582. /*  Print out information about main program to be made */
  583. /*                                                      */
  584. /********************************************************/
  585.  
  586. void ProcessMain(struct ProducerNode *pn)
  587. {
  588.     BPTR   MainFile = 0;
  589.     UBYTE  Name[512];
  590.     
  591.     strcpy( &Name[ 0 ], ProjectName );
  592.     AddEnding( &Name[ 0 ], "Main.c" );
  593.     
  594.     if ( pn->pn_CodeOptions[6])
  595.         if ( ProducerWindowWriteMain( pn, &Name[0]))
  596.             {
  597.             if ( ! (MainFile = OpenOutputFile("Main.c")))
  598.                 return ;
  599.             
  600.             MyFPrintf( MainFile  , "/* Designer Producer Main Program Source */");
  601.             
  602.             LineCount+=1;
  603.             
  604.             Close(MainFile);
  605.             }
  606. }
  607.  
  608. /********************************************************/
  609. /*                                                      */
  610. /*  Process each file in turn and create data           */
  611. /*                                                      */
  612. /********************************************************/
  613.  
  614. int ProcessFile(char * filename)
  615. {
  616.     long   error = 0;
  617.     struct WindowNode * wn;
  618.     struct MenuNode *mn;
  619.     struct ImageNode *in;
  620.     struct ScreenNode *sn;
  621.     long   done = 0;
  622.     long   abort = 0;
  623.     
  624.     /*  Load the file and process the data in it     */
  625.     /*  Updating the linecout regularly and checking */
  626.     /*  for user aborts                              */
  627.     
  628.     ProjectName = filename;
  629.     
  630.     LineCount = 0;
  631.     SetProducerWindowLineNumber( pn, LineCount);
  632.         
  633.     SetProducerWindowFileName(pn,filename);
  634.     SetProducerWindowAction(pn, "Loading");
  635.     
  636.     error = LoadDesignerData(pn, filename);
  637.     if (error==0)
  638.         {
  639.         
  640.         if ( ! (OutputFile = OpenOutputFile(".c")))
  641.             {
  642.             SetProducerWindowAction(pn, "Could not open output file.");
  643.             Delay(50);
  644.             return 2;
  645.             }
  646.         
  647.         MyFPrintf( OutputFile, "/* Designer Producer Source Code */\n");
  648.         MyFPrintf( OutputFile, "Process File : %s\n",filename);
  649.         LineCount += 2;
  650.         
  651.         wn = pn->pn_WindowList.mlh_Head;
  652.         mn = pn->pn_MenuList.mlh_Head;
  653.         in = pn->pn_ImageList.mlh_Head;
  654.         sn = pn->pn_ScreenList.mlh_Head;
  655.     
  656.         while ((done == 0)&&(abort==0))
  657.             {
  658.             
  659.             if (wn->wn_Succ)
  660.                 {
  661.                 ProcessWindow(wn);
  662.                 wn = wn->wn_Succ;
  663.                 }
  664.             else
  665.                 if (mn->mn_Succ)
  666.                     {
  667.                     ProcessMenu(mn);
  668.                     mn = mn->mn_Succ;
  669.                     }
  670.                 else
  671.                     if (in->in_Succ)
  672.                         {
  673.                         ProcessImage(in);
  674.                         in = in->in_Succ;
  675.                         }
  676.                     else
  677.                         if (sn->sn_Succ)
  678.                             {
  679.                             ProcessScreen(sn);
  680.                             sn = sn->sn_Succ;
  681.                             }
  682.                         else
  683.                             done = 1;
  684.             
  685.             abort = ProducerWindowUserAbort(pn);
  686.             SetProducerWindowLineNumber( pn, LineCount);
  687.             
  688.             }
  689.             
  690.         if (abort == 0)
  691.             PrintLocale(pn);
  692.         
  693.         SetProducerWindowLineNumber( pn, LineCount);
  694.         
  695.         Close(OutputFile);
  696.         
  697.         if (abort == 0)
  698.             abort = ProducerWindowUserAbort(pn);
  699.         
  700.         if (abort == 0)
  701.             ProcessMain(pn);
  702.         
  703.         SetProducerWindowLineNumber( pn, LineCount);
  704.         
  705.         FreeDesignerData(pn);
  706.         }
  707.     else
  708.         {
  709.         SetProducerWindowAction(pn, LoadErrors[error]);
  710.         Delay(50);
  711.         }
  712.     return error;
  713. }
  714.  
  715. /*************************************************/
  716. /*                                               */
  717. /* CLI Startup, finds all files that match each  */
  718. /* parameter and attempts to parse each file.    */
  719. /* Program exits on a load failure.              */
  720. /*                                               */
  721. /*************************************************/
  722.  
  723.  
  724. int main(ac, av)
  725. short ac;
  726. char *av[];
  727. {
  728.     short i;
  729.     long error;
  730.     struct AnchorPath *anchorpath;
  731.     BPTR curdir;
  732.     
  733.     pn=(struct ProducerNode *)GetProducer();
  734.     if (pn)
  735.         {
  736.         if (OpenProducerWindow(pn,"Demonstration Handler"))
  737.             {
  738.             if (ac==1)
  739.                 {
  740.                 SetProducerWindowAction(pn,"No Files");
  741.                 Delay(50);
  742.                 }
  743.             else
  744.                 {
  745.                 anchorpath = (struct AnchorPath *)AllocVec(sizeof(struct AnchorPath),MEMF_CLEAR);
  746.                 if (anchorpath)
  747.                     {
  748.                     for (i = 1; i<ac; ++i)
  749.                         {
  750.                         error = MatchFirst(av[i],anchorpath);
  751.                         while (error==0)
  752.                             {
  753.                             
  754.                             curdir = CurrentDir(anchorpath->ap_Last->an_Lock);
  755.                             error  = ProcessFile(&anchorpath->ap_Info.fib_FileName[0]);
  756.                             CurrentDir(curdir);
  757.                             
  758.                             if (error==0)
  759.                                 error = MatchNext(anchorpath);
  760.                                 
  761.                             }
  762.                         
  763.                         MatchEnd(anchorpath);
  764.                         }
  765.                     FreeVec(anchorpath);
  766.                     }
  767.                 }
  768.             CloseProducerWindow(pn);
  769.             }
  770.         FreeProducer(pn);
  771.         }
  772.     return(0);
  773. }
  774.  
  775.